<%@page import="edu.gatech.team404.Lab"%>
<%@page import="edu.gatech.team404.dal.LabDAL"%>
<%@page import="edu.gatech.team404.Course"%>
<%@page import="edu.gatech.team404.dal.CourseDAL"%>
<%@page import="edu.gatech.team404.tool.StatusCode"%>
<%@page import="java.util.ArrayList"%>
<%@ page import="java.net.URLDecoder"%>

<%@include file="header.jsp" %>

<div id="content">
    <%@include file="sidebar.jsp" %>
    
    <%@include file="toolbar.jsp" %>
    
    <div id="main">
    	<h1 align="center">Lab</h1>
    	
    	<div id="create">
	    	<div class="status">
		    	<%
		    	Object status = session.getAttribute("labCreationStatus");
	    		if (status != null) {
	    			StatusCode code = (StatusCode) status;
	    			switch (code) {
		    			case LAB_CREATE_SUCCESS :
		    				out.println("<p style=\"color:blue;\">");
							out.println("Lab has been successfully created.");
							out.println("</p>");
		    				break;
		    			case LAB_CREATE_FAIL :
		    				out.println("<p style=\"color:red;\">");
							out.println("Cannot create a Lab. Please try again later.");
							out.println("</p>");
		    				break;
		    			case LAB_CREATE_INVALID_DATA :
		    				out.println("<p style=\"color:red;\">");
							out.println("Invalid input(s).");
							out.println("</p>");
		    				break;
	    			}
	    		}
		    	%>
	    	</div>
	    	<div class="viewTable" style="margin-bottom:20px;">
		    	<form action="LabServlet" method="post">
		    		<table cellpadding="10">
		    			<tr>
		    				<th align="right">Course Name</th>
		    				<td align="left"><input type="text" readonly="readonly" name="courseName" value='<%= URLDecoder.decode(request.getParameter("course"),"UTF-8")  %>'></td>
		    			</tr>
		    			<tr>
		    				<th align="right">Name</th>
		    				<td align="left"><input type="text" name="name" value="" size="50" maxlength="15"/></td>
		    			</tr>
		    			<tr>
		    				<th align="right">Start Date</th>
		    				<td align="left"><input type="text" name="startDate" value="" size="50" maxlength="15"/></td>
		    			</tr>
		    			<tr>
		    				<th align="right">End Date</th>
		    				<td align="left"><input type="text" name="endDate" value="" size="50" maxlength="15"/></td>
		    			</tr>
		    			<tr>
		    				<th align="right">Team Assignment</th>
		    				<td>
		    					<select name="teamAssignment">
		    						<option value="Individual">Individual</option>
		    						<option value="Random">Random</option>
		    						<option value="Self Select">Self Select</option>
		    					</select>
		    				</td>
		    			</tr>
		    			<tr>
		    				<th align="right">Team Size</th>
		    				<td>
		    					<select name="teamSize">
		    						<option value="1">1</option>
		    						<option value="2">2</option>
		    						<option value="3">3</option>
		    						<option value="4">4</option>
		    						<option value="5">5</option>
		    						<option value="6">6</option>
		    						<option value="7">7</option>
		    						<option value="8">8</option>
		    						<option value="9">9</option>
		    					</select>
		    				</td>
		    			</tr>
		    			<tr>
		    				<td colspan="2" align="center">
		    					<input type="submit" value="Create Lab!" />
		    				</td>
		    			</tr>
		    		</table>
		    	</form>
	    	</div>
	    </div>
    	
    	<div id="review">
	    	<table class="viewTable" border="1" cellpadding="10">
	    		<tr>
	    			<th>Course Name</th>
	    			<th>Name</th>
	    			<th>Start Date</th>
	    			<th>End Date</th>
	    			<th>Team Assignment</th>
	    			<th>Team Size</th>
	    		</tr>
	
		    	<% 
		    	LabDAL lDal = new LabDAL();
		    	String coursse = URLDecoder.decode(request.getParameter("course"), "UTF-8");
		    	ArrayList<Lab> labs = (ArrayList<Lab>) lDal.getAllLabsInCourse(coursse);
		    	lDal.close();
		    	
	    		for (Lab lubs : labs) {
	    			if (lubs != null) {
	    				out.println ("<tr>");
	    				out.println ("<td>" + lubs.getCourseName() + "</td>");
	    				out.println ("<td>" + lubs.getName() + "</td>");
	    				out.println ("<td>" + lubs.getStartDate() + "</td>");
	    				out.println ("<td>" + lubs.getEndDate() + "</td>");
	    				out.println ("<td>" + lubs.getTeamAssignment() + "</td>");
	    				out.println ("<td>" + lubs.getTeamSize() + "</td>");
	    				out.println ("</tr>");
	    			}
	    		}
	    		%>
	    	
	    	</table>
	    </div>
	    
	    <div id="update">
	    	<div class="status">
		    	<%
		    		status = session.getAttribute("labUpdateStatus");
		    		if (status != null) {
		    			StatusCode code = (StatusCode) status;
		    			switch (code) {
			    			case LAB_UPDATE_SUCCESS :
			    				out.println("<p style=\"color:blue;\">");
								out.println("Lab has been successfully updated.");
								out.println("</p>");
			    				break;
			    			case LAB_UPDATE_FAIL :
			    				out.println("<p style=\"color:red;\">");
								out.println("Cannot update the Lab. Please try again later.");
								out.println("</p>");
			    				break;
			    			case LAB_UPDATE_INVALID_DATA :
			    				out.println("<p style=\"color:red;\">");
								out.println("Invalid input(s).");
								out.println("</p>");
			    				break;
		    			}
		    		}
		    	%>
	    	</div>
	    	
	    	<div>
		    	<form name="updateLabForm" action="UpdateLab" method="post">
		    		<input type= "hidden" name="courseName" value='<%=request.getParameter("course") %>'>
		    		<table class="viewTable" cellpadding="10">
		    			<tr>
		    				<th align="right">Lab</th>
		    				<td>
			    				<select name="labId" onChange="Script404.labUpdate(this.value, 'updateLabForm')"> 
			    					<option value="">Select lab</option> 
				    				<%
				    					for(Lab lab : labs){
				    						if (lab != null) {
				    							out.println ("<option value=\"" + lab.getId() + "\">" + lab.getName() + "</option>");
				    						}
				    					}
				    				%>
		    					</select>
		    				</td>
		    			</tr>
		    			<tr>
		    				<th align="right">Name</th>
		    				<td align="left"><input type="text" name="name" value="" size="50" maxlength="255"/></td>
		    			</tr>
		    			<tr>
		    				<th align="right">Start Date</th>
		    				<td align="left"><input type="text" name="startDate" value="" size="50" maxlength="15"/></td>
		    			</tr>
		    			<tr>
		    				<th align="right">End Date</th>
		    				<td align="left"><input type="text" name="endDate" value="" size="50" maxlength="15"/></td>
		    			</tr>
		    			<tr>
		    				<th align="right">Team Assignment</th>
		    				<td>
		    					<select name="teamAssignment">
		    						<option value="Unknown">Select assignment</option>
		    						<option value="Individual">Individual</option>
		    						<option value="Random">Random</option>
		    						<option value="Self Select">Self Select</option>
		    					</select>
		    				</td>
		    			</tr>
		    			<tr>
		    				<th align="right">Team Size</th>
		    				<td>
		    					<select name="teamSize">
		    						<option value="1">1</option>
		    						<option value="2">2</option>
		    						<option value="3">3</option>
		    						<option value="4">4</option>
		    						<option value="5">5</option>
		    						<option value="6">6</option>
		    						<option value="7">7</option>
		    						<option value="8">8</option>
		    						<option value="9">9</option>
		    					</select>
		    				</td>
		    			</tr>
		    			<tr>
		    				<td colspan="2" align="center">
		    					<input type="submit" value="Update Lab!" />
		    				</td>
		    			</tr>
		    		</table>
		    	</form>
	    	</div>
	    </div>
	    
	    <div id="delete">
	    	<div class="status">
		    	<%
		    		status = session.getAttribute("labDeleteStatus");
		    		if (status != null) {
		    			StatusCode code = (StatusCode) status;
		    			switch (code) {
			    			case LAB_DELETE_SUCCESS :
			    				out.println("<p style=\"color:blue;\">");
								out.println("Lab has been successfully deleted.");
								out.println("</p>");
			    				break;
			    			case LAB_DELETE_FAIL :
			    				out.println("<p style=\"color:red;\">");
								out.println("Cannot delete the Lab. Please try again later.");
								out.println("</p>");
			    				break;
		    			}
		    		}
		    	%>
	    	</div>
	    	
	    	<div>
		    	<form action="DeleteLab" method="post">
		    		<table class="viewTable" cellpadding="10">
		    			<tr>
		    				<th align="right">Lab name</th>
		    				<td>
			    				<select name="labId" onChange="Script404.labDesc(this.value, 'labDescription')">
			    					<option value="">Select lab</option>
				    				<% 
				    					for(Lab lab : labs){
				    						if (lab != null) {
				    		    				out.println ("<option value=\"" + lab.getId() + "\">" + lab.getName() + "</option>");
				    						}
				    					}
				    				%>
		    					</select>
		    				</td>
		    			</tr>
		    			<tr>
		    				<td colspan="2">
		    					<input type= "hidden" name="courseName" value='<%=request.getParameter("course") %>'>
		    				</td>
		    			</tr>
		    			<tr>
							<td colspan=2 align""=left">
								<p id="labDescription"></p>
							</td>
						</tr>
		    			<tr>
		    				<td colspan="2" align="center">
		    					<input type="submit" value="Delete Lab!" />
		    				</td>
		    			</tr>
		    		</table>
		    	</form>
	    	</div>
	    </div>
	    
	    <script type="text/javascript"> 
			Script404.initShow("<%= session.getAttribute("feed") %>"); 	   
		</script>
    </div>
</div>

<%@include file="footer.jsp" %>